package Book;

public class Book implements Cloneable,Comparable<Book>{

	public String name;
	public Author author;
	public double price;
	public int qty;
	
	public Book(String name, Author author, double price) {
		this.name = name;
		this.author = author;
		this.price = price;
	}

	public Book(String name, Author author, double price, int qty) {
		this.name = name;
		this.author = author;
		this.price = price;
		this.qty = qty;
	}

	public String getName() {
		return name;
	}

	public Author getAuthor() {
		return author;
	}

    public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public int getQty() {
		return qty;
	}

	public void setQty(int qty) {
		this.qty = qty;
	}

	@Override
	public String toString() {
		return "Book [name=" + name + ", " + this.author.toString() + ", price=" + price + ", qty=" + qty + "]";
	}
	
	public Object clone() {
		Book o = null;
		try {
			o = (Book)super.clone();
			o.author = (Author) author.clone();
			return o;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return o;
	}
	
	public int hashCode(){
		String s = name + author.email;
		return s.hashCode();
	}
	
	public boolean equals(Object anotherObject) {
        if(!(anotherObject instanceof Book)) return false;
        Book anotherBook = (Book)anotherObject;
        return name.equals(anotherBook.name) && author.email.equals(anotherBook.author.email);
    }

	@Override
	public int compareTo(Book o) {
		return name.compareTo(o.name);
	}
	
}
